home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / test / utiltest.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  4.8 KB  |  119 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from StringIO import StringIO
  5. import os
  6. import tempfile
  7. from test.framework import DemocracyTestCase
  8. import download_utils
  9. import util
  10. import xhtmltools
  11.  
  12. class FakeStream:
  13.     """Fake streams are used for the AutoflushingStream test.  They don't
  14.     really do much, except check that write is always called with a string
  15.     object (unicode won't always work when writing to stdout).
  16.     """
  17.     
  18.     def write(self, out):
  19.         if not isinstance(out, str):
  20.             raise ValueError('Got non-string object (%s) from autoflushing stream' % str.__class__)
  21.         
  22.  
  23.     
  24.     def flush(self):
  25.         pass
  26.  
  27.  
  28.  
  29. class AutoflushingStreamTest(DemocracyTestCase):
  30.     
  31.     def setUp(self):
  32.         DemocracyTestCase.setUp(self)
  33.         self.stream = FakeStream()
  34.         self.afs = util.AutoflushingStream(self.stream)
  35.  
  36.     
  37.     def testBasicWrite(self):
  38.         self.afs.write('Hello World\n')
  39.         self.afs.write('')
  40.         self.afs.write('LotsofData' * 200)
  41.  
  42.     
  43.     def testUnicodeWrite(self):
  44.         self.afs.write(u'├╕')
  45.  
  46.  
  47.  
  48. class UtilTest(DemocracyTestCase):
  49.     
  50.     def testAbsolutePathToFileURL(self):
  51.         testPaths = {
  52.             '/ben/dean/kawamura': 'file:///ben/dean/kawamura',
  53.             '/eight/bit/path/\xe4': 'file:///eight/bit/path/%E4',
  54.             u'/unicode/path/├ñ': 'file:///unicode/path/%C3%A4' }
  55.         for source, target in testPaths.items():
  56.             self.assertEquals(util.absolutePathToFileURL(source), target)
  57.         
  58.  
  59.     
  60.     def testStringify(self):
  61.         t = [
  62.             ('', None, ''),
  63.             ('abc', None, 'abc'),
  64.             (5, None, '5'),
  65.             (5.5, None, '5.5'),
  66.             (u'abc', None, 'abc'),
  67.             (u'abc├ñ', None, 'abcä'),
  68.             (u'abc├ñ', 'replace', 'abc?')]
  69.         for i, h, o in t:
  70.             if h == None:
  71.                 self.assertEquals(util.stringify(i), o)
  72.                 continue
  73.             self.assertEquals(util.stringify(i, h), o)
  74.         
  75.  
  76.     
  77.     def testRandomString(self):
  78.         ret = util.random_string(0)
  79.         self.assertEquals(len(ret), 0)
  80.         for length in (1, 5, 10):
  81.             ret = util.random_string(length)
  82.             self.assertEquals(len(ret), length)
  83.             self.assertEquals(ret.isalpha(), True)
  84.         
  85.  
  86.  
  87.  
  88. class XHTMLToolsTest(DemocracyTestCase):
  89.     
  90.     def testMultipartEncode(self):
  91.         vars = {
  92.             'foo': u'123' }
  93.         files = {
  94.             'baz': {
  95.                 'filename': 'binarydata.zip',
  96.                 'mimetype': 'application/octet-stream',
  97.                 'handle': StringIO('\xf8') } }
  98.         (boundary, data) = xhtmltools.multipartEncode(vars, files)
  99.  
  100.  
  101.  
  102. class DownloadUtilsTest(DemocracyTestCase):
  103.     
  104.     def checkCleanFilename(self, filename, test_against):
  105.         self.assertEquals(download_utils.cleanFilename(filename), test_against)
  106.  
  107.     
  108.     def testCleanFilename(self):
  109.         self.checkCleanFilename('normalname', 'normalname')
  110.         self.checkCleanFilename('a:b?c>d<e|f*/g\\h"\'', 'abcdefgh')
  111.         self.checkCleanFilename('', '_')
  112.         longFilename = 'booya' * 100
  113.         longExtension = '.' + 'foo' * 20
  114.         self.checkCleanFilename(longFilename, longFilename[:100])
  115.         self.checkCleanFilename('abc' + longExtension, 'abc' + longExtension)
  116.         self.checkCleanFilename(longFilename + longExtension, longFilename[:50] + longExtension[:50])
  117.  
  118.  
  119.